package com.example.bbook.controller;

import com.example.bbook.entity.GoodsEntity;
import com.example.bbook.entity.OrderEntity;
import com.example.bbook.services.CRUDServiceInterface;
import com.example.bbook.services.OrderService;
import com.example.bbook.util.PageTool;
import com.example.bbook.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService baseService;

    @RequestMapping(value = "/list")
    public Response getUserList(PageTool pageTool, OrderEntity data) {
        return Response.successful(baseService.findAll(pageTool, data));
    }

    @RequestMapping(value = "/add")
    public Response addUserById(@RequestBody OrderEntity user) {
        return baseService.addOrder(user);
    }

    @RequestMapping("/delete")
    public Response deleteUserById(@RequestBody Integer[] ids) {
        Boolean deleteUserRes = baseService.deleteByIds(ids);
        if (deleteUserRes) {
            return Response.successful();
        }
        return Response.fail();
    }

    @RequestMapping("/update")
    public Response updateUserById(@RequestBody OrderEntity user) {
        Boolean updateUserRes = baseService.updateById(user);
        if (updateUserRes) {
            return Response.successful();
        }
        return Response.fail();
    }
}
